package com.tianqu.tms.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.dao.DectCodesDao;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dto.DectCodesDto;

/**
 * 检测报告字典表
 * 
 * @author tianshifu
 *
 */
public class DectCodes extends TmsEntity {

	/**
	 * Serializable id
	 */
	private static final long serialVersionUID = 8941684905894069063L;

	private long ID;// 主键ID

	private int itemId;// 数据类别

	private String itemCode;// 缺陷描述

	private String itemValue;// 缺陷代码

	/******************* 定义获取code信息类型 *************************/
	
	public final static int TRAFFIC_CAR = 101;//事故车三大项
	
	public final static int  ACCIDENT_CAR_BODY_CHECK = 102;//事故车车体结果检查
	
	public final static int  CAR_EXTERIOR = 103;//外饰
	
	public final static int  CAR_INTERIOR = 104;//内饰
	
	public final static int  ENGINE_DRIVE_BRAKING = 105;//发动机传动制动
	
	public final static int  ELECTRONIC_EQUIPMENT = 106;//电子设备 
	
	public final static int  CAR_OTHER_PARTS = 107;//其他部位
	
	public final static int  SENIOR_CARDECT_ACCIDENT_CHECK = 108;//高级检测事故车判定检测
	
	public final static int  SENIOR_CARDECT_ENGINE_CHECK = 109;//高级检测发动机舱检查项目
	
	public final static int  SENIOR_CARDECT_COCKPIT_STARTUP_ROAD_CHECK = 110;//高级检测驾驶舱、启动和路试
	
	public final static int  CAR_SOURSE = 111;//车辆信息来源
	
	public final static int  USER_TYPE = 112;//权限类型
	
	public final static int DETECT_MODE = 113;//检测模式
	
	public final static int  DATA_STATUS = 114;//状态
	
	public final static int  EIGHT_VEHICLE_CONFIGURATION = 115;//整车八大配置
	
	public final static int  IMAGE_TYPE = 116;//图片类型
	
	public final static int  IF_ACCIDENT_CAR = 117;//事故车
	
	public final static int  FUEL_TYPE= 118;//燃油方式
	
	public final static int  GEARBOX_TYPE= 119;//变速箱类型
	
	public final static int  NATURE_TYPE= 120;//使用性质
	
	public final static int  SENIOR_CARDECT_LEVEL= 121;//高级检测等级

	
	
	//
	/**
	 * 实例化codes表
	 * 
	 * @return
	 */
	private static DectCodes instance;

	List<DectCodes> codes = null;

	/**
	 * 加载Codes
	 * 
	 * @return
	 * @throws TmsDaoException
	 */
	public static DectCodes getInstance() throws TmsDaoException {
		if (null == instance) {
			instance = new DectCodes();
			instance.init();
		}
		return instance;
	}

	/**
	 * 实例化Code
	 * 
	 * @throws TmsDaoException
	 */
	public void init() throws TmsDaoException {
		codes = new ArrayList<DectCodes>();
		setCodes();
	}

	/**
	 * 获取Codes信息存在静态codes中
	 * @throws TmsDaoException
	 */
	public void setCodes() throws TmsDaoException {
		DectCodesDao dao = (DectCodesDao) TmsDao.getInstance(TmsDao.DECT_CODE);
		List<DectCodesDto> list = dao.findCodesList();
		for (int i = 0; i < list.size(); i++) {
			DectCodesDto dto = (DectCodesDto) list.get(i);
			DectCodes entity = new DectCodes();
			entity.setItemId(dto.getItemId());
			entity.setItemCode(dto.getItemCode());
			entity.setItemValue(dto.getItemValue());
			codes.add(entity);
		}
	}

	/**
	 * 根据itemId获取code信息
	 * 
	 * @param itemId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public  List getCodeslistByItemId(int itemId) {
		Map map = null;// 用于存储itemCode和itemValue
		List list = new ArrayList();
		for (int i = 0; i < codes.size(); i++) {
			DectCodes dto = (DectCodes) codes.get(i);
			if (dto.getItemId() == itemId) {
				map = new HashMap();
				map.put("itemCode", dto.getItemCode());
				map.put("itemValue", dto.getItemValue());
				list.add(map);
			}
		}	
		return list;
	}

	/**
	 * 根据ItemId和ItemCode获取具体itemValue值
	 * 
	 * @param itemId
	 * @param itemCode
	 * @return
	 */
	public String getItemValueByItemIdAndItemCode(int itemId, String itemCode) {
		String str = TmsConstants.BLANK;
		for (int i = 0; i < codes.size(); i++) {
			DectCodes entity = (DectCodes) codes.get(i);
			if (entity.getItemId() == itemId && entity.getItemCode() .equals(itemCode) ) {
				return entity.getItemValue();
			}
		}
		return str;
	}
	/**
	 *  根据itemId和itemValue获取itemCode
	 * @param itemId
	 * @param itemValue
	 * @return
	 */
	public String getItemCodeByItemIdAndItemValue(int itemId,String itemValue){
		String code = TmsConstants.BLANK;
		for(int i=0;i<codes.size();i++)
		{
			DectCodes entity = (DectCodes)codes.get(i);
			if(entity.getItemId() == itemId && itemValue.equals(entity.getItemValue()))
			{
				return entity.getItemCode();
			}
		}
		return code;
	}

	public long getID() {
		return ID;
	}

	public void setID(long iD) {
		ID = iD;
	}

	public int getItemId() {
		return itemId;
	}

	public void setItemId(int itemId) {
		this.itemId = itemId;
	}


	public String getItemCode() {
		return itemCode;
	}

	public void setItemCode(String itemCode) {
		this.itemCode = itemCode;
	}

	public String getItemValue() {
		return itemValue;
	}

	public void setItemValue(String itemValue) {
		this.itemValue = itemValue;
	}

	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub
		
	}

}
